package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.member.Reservation;
import com.zzyl.nursing.service.member.IReservationService;
import com.zzyl.nursing.vo.member.CountByTimeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 预约信息Controller
 * 
 * @author zzyl_mh
 * @date 2025-08-18
 */
@Api(tags = "预约信息管理")
@RestController
@RequestMapping("/member/reservation")
public class ReservationController extends BaseController
{
    @Autowired
    private IReservationService reservationService;

    /**
     * 查询预约信息列表
     */
    @ApiOperation("查询预约信息列表")
    @GetMapping("/page")
    public R<TableDataInfo> page(@ApiParam("预约信息查询条件") Reservation reservation)
    {
        startPage();
        List<Reservation> list = reservationService.selectReservationList(reservation);
        return R.ok(getDataTable(list)) ;
    }


    /**
     * 新增预约信息
     */
    @ApiOperation("新增预约信息")
    @PostMapping
    public AjaxResult add(@ApiParam("预约信息信息") @RequestBody Reservation reservation)
    {

        return toAjax(reservationService.insertReservation(reservation));
    }

    /**
     * 修改预约信息
     */
    @ApiOperation("取消预约")
    @PutMapping("/{id}/cancel")
    public AjaxResult edit(@ApiParam("预约id") @PathVariable Long id)
    {
        reservationService.updateReservation(id);
        return success();
    }



    /**
     * 查询每个时间段剩余预约次数
     * @return
     */
    @GetMapping("/countByTime")
    @ApiOperation("查询当天取消预约数量")
    public AjaxResult countByTime(long time)
    {
        List<CountByTimeVo> list = reservationService.countByTime(time);
        return success(list);
    }

    /**
     * 查询当天取消预约数量
     * @return
     */
    @GetMapping("/cancelled-count")
    @ApiOperation("查询当天取消预约数量")
    public AjaxResult cancelledCount()
    {
        long resultCount =  reservationService.cancelledCount();
        return success(resultCount);
    }


}
